﻿package mortal.game.scene3D.map3D.sceneInfo
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.model.*;
    import mortal.game.scene3D.map3D.util.*;

    public class SceneInfo extends Object
    {
        private var _sMapDefine:SMapDefine;
        private var _sharpsUpdater:Dictionary;
        private var _sharpsMap:Dictionary;
        private var _sharpsRawData:Dictionary;
        private var _npcInfos:Array;
        private var _passInfos:Array;
        private var _sceneEffects:Array;
        private var _jumpPoints:Array;
        private var _bossRefreshs:Array;
        private var _shadowAreaList:Array;
        private var _xLightList:Array;
        private var _musicAreas:Vector.<MusicAreaInfo>;
        private var _sceneViewTimes:int;
        private var _buildInfos:Array;
        private var _statueInfos:Array;
        private var _crossMainCityStatueInfos:Array;
        private var _fishingPoints:Array;
        private var _bossRefreshDic:Dictionary;
        private var _bossArea:Array;
        private var _isSpa:Boolean = false;
        private var _limitInfo:SceneLimitInfo;
        private var _playerShowPartsInfos:ScenePlayerShowPartsInfo;
        private var _dataParser:SceneInfoParser;
        private var _refreshInfoToPlan:Dictionary;

        public function SceneInfo()
        {
            this._bossRefreshs = [];
            this._shadowAreaList = [];
            this._xLightList = [];
            this._musicAreas = new Vector.<MusicAreaInfo>;
            this._bossRefreshDic = new Dictionary();
            this._bossArea = [];
            this._refreshInfoToPlan = new Dictionary();
            this._sMapDefine = new SMapDefine();
            this._npcInfos = [];
            this._passInfos = [];
            this._sceneEffects = [];
            this._jumpPoints = [];
            this._buildInfos = [];
            this._crossMainCityStatueInfos = [];
            this._limitInfo = new SceneLimitInfo();
            this._playerShowPartsInfos = new ScenePlayerShowPartsInfo();
            this._dataParser = new SceneInfoParser(GameMapUtil.mapWidth, GameMapUtil.mapHeight);
            return;
        }// end function

        public function get limitInfo() : SceneLimitInfo
        {
            return this._limitInfo;
        }// end function

        public function get jumpPoints() : Array
        {
            return this._jumpPoints;
        }// end function

        public function readObj(param1:Object) : void
        {
            this._sMapDefine = this._dataParser.fromObj(param1);
            this._shadowAreaList = this._dataParser.readShadowList(param1);
            this._sceneViewTimes = this._dataParser.readSceneViewTimes(param1);
            this._limitInfo.limitValue = this._sMapDefine.restrictionType;
            this._playerShowPartsInfos.showPartsValue = this._sMapDefine.showLimit;
            this.parseClientData();
            this.readBossAreaInfo(param1);
            this.readXLightList(this._dataParser.readXLight(param1));
            this.readMusicAreas(this._dataParser.readMusic(param1));
            return;
        }// end function

        public function get statueInfos() : Array
        {
            return this._statueInfos;
        }// end function

        public function get sharpsMap() : Dictionary
        {
            return this._sharpsMap;
        }// end function

        public function set sharpsUpdater(param1:Dictionary) : void
        {
            this._sharpsUpdater = param1;
            return;
        }// end function

        public function get sharpsUpdater() : Dictionary
        {
            return this._sharpsUpdater;
        }// end function

        public function get buildInfos() : Array
        {
            return this._buildInfos;
        }// end function

        public function get effectInfos() : Array
        {
            return this._sceneEffects;
        }// end function

        public function get shadowAreaInfos() : Array
        {
            return this._shadowAreaList;
        }// end function

        public function get passInfos() : Array
        {
            return this._passInfos;
        }// end function

        public function get xLightList() : Array
        {
            return this._xLightList;
        }// end function

        public function get musicAreas() : Vector.<MusicAreaInfo>
        {
            return this._musicAreas;
        }// end function

        public function get npcInfos() : Array
        {
            return this._npcInfos;
        }// end function

        public function get crossMainCityStatueInfos() : Array
        {
            return this._crossMainCityStatueInfos;
        }// end function

        public function get sMapDefine() : SMapDefine
        {
            return this._sMapDefine;
        }// end function

        public function get bossRefreshs() : Array
        {
            return this._bossRefreshs;
        }// end function

        public function get bossArea() : Array
        {
            return this._bossArea;
        }// end function

        public function isXLightGrid(param1:int, param2:int) : Boolean
        {
            return this._xLightList[param1 * 1000 + param2] as Boolean;
        }// end function

        public function get isEnterByJumpScene() : Boolean
        {
            return this._sceneViewTimes > 0;
        }// end function

        public function get sceneViewTimes() : Number
        {
            return this._sceneViewTimes / 10;
        }// end function

        public function getBossRefreshInfoByLevel(param1:int, param2:int) : BossRefreshInfo
        {
            var _loc_3:int = 0;
            var _loc_5:BossRefreshInfo = null;
            var _loc_6:TBoss = null;
            var _loc_4:* = this._bossRefreshs.length;
            while (_loc_3 < _loc_4)
            {
                
                _loc_5 = this._bossRefreshs[_loc_3];
                _loc_6 = _loc_5.getNormalBoss();
                if (_loc_6 && _loc_6.level >= param1 && _loc_6.level <= param2)
                {
                    return _loc_5;
                }
                _loc_3++;
            }
            return null;
        }// end function

        public function getBossRefreshInfoByPlan(param1:int) : Array
        {
            var _loc_2:int = 0;
            var _loc_4:BossRefreshInfo = null;
            if (this._refreshInfoToPlan.hasOwnProperty(param1))
            {
                return this._refreshInfoToPlan[param1];
            }
            var _loc_3:* = this._bossRefreshs.length;
            var _loc_5:Array = [];
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = this._bossRefreshs[_loc_2];
                if (_loc_4.plan == param1)
                {
                    _loc_5.push(_loc_4);
                }
                _loc_2++;
            }
            this._refreshInfoToPlan[param1] = _loc_5;
            return _loc_5;
        }// end function

        public function getBossRefreshInfoByCode(param1:int) : BossRefreshInfo
        {
            var _loc_2:int = 0;
            var _loc_4:BossRefreshInfo = null;
            var _loc_3:* = this._bossRefreshs.length;
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = this._bossRefreshs[_loc_2];
                if (_loc_4.hasBossCode(param1))
                {
                    return _loc_4;
                }
                _loc_2++;
            }
            return null;
        }// end function

        public function gotoNextMapPoint(param1:int) : SPassPoint
        {
            var _loc_2:SPassPoint = null;
            var _loc_3:SPassTo = null;
            for each (_loc_2 in this._passInfos)
            {
                
                for each (_loc_3 in _loc_2.passTo)
                {
                    
                    if (_loc_3.mapId == param1)
                    {
                        return _loc_2;
                    }
                }
            }
            return null;
        }// end function

        public function getNpcInfo(param1:int) : NPCInfo
        {
            var _loc_2:NPCInfo = null;
            for each (_loc_2 in this.npcInfos)
            {
                
                if (_loc_2.tnpc && _loc_2.tnpc.code == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getEffectData(param1:String) : SceneEffectData
        {
            var _loc_2:SceneEffectData = null;
            for each (_loc_2 in this.effectInfos)
            {
                
                if (_loc_2.key == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getPassPointInfo(param1:int) : SPassPoint
        {
            var _loc_2:SPassPoint = null;
            for each (_loc_2 in this.passInfos)
            {
                
                if (_loc_2.passPointId == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function readBossRefreshPoint(param1:Object) : void
        {
            var _loc_2:BossRefreshInfo = null;
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            if (param1 == null)
            {
                return;
            }
            this._bossRefreshs = [];
            var _loc_3:* = param1["refreshPoint"];
            var _loc_6:* = _loc_3.length;
            while (_loc_5 < _loc_6)
            {
                
                _loc_4 = _loc_3[_loc_5];
                _loc_2 = new BossRefreshInfo();
                _loc_2.updateData(param1["mapId"], _loc_4["point"]["x"], _loc_4["point"]["y"], _loc_4["plan"], _loc_4["subPoints"]);
                this._bossRefreshs.push(_loc_2);
                this._bossRefreshDic[_loc_4["plan"]] = _loc_2;
                _loc_5++;
            }
            this._bossRefreshs.sortOn("plan");
            return;
        }// end function

        public function readBossAreaInfo(param1:Object) : void
        {
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:Object = null;
            var _loc_6:BossAreaInfo = null;
            this._bossArea.length = 0;
            if (param1.areas != null)
            {
                _loc_2 = param1.areas as Array;
                _loc_4 = _loc_2.length;
                while (_loc_3 < _loc_4)
                {
                    
                    _loc_5 = _loc_2[_loc_3];
                    _loc_6 = new BossAreaInfo();
                    _loc_6.name = _loc_5.name;
                    _loc_6.id = _loc_5.areaId;
                    _loc_6.mapId = _loc_5.mapId;
                    _loc_6.px = _loc_5.point.x;
                    _loc_6.py = _loc_5.point.y;
                    _loc_6.plans = _loc_5.plans;
                    _loc_6.updateData(this._bossRefreshDic);
                    this._bossArea.push(_loc_6);
                    _loc_3++;
                }
            }
            return;
        }// end function

        private function readXLightList(param1:Array) : void
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:Point = null;
            this._xLightList = [];
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2];
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    _loc_5 = _loc_3[_loc_4];
                    this._xLightList[_loc_5.x * 1000 + _loc_5.y] = true;
                    _loc_4++;
                }
                _loc_2++;
            }
            return;
        }// end function

        public function readMusicAreas(param1:Array) : void
        {
            var _loc_3:MusicAreaInfo = null;
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2];
                this._musicAreas.push(_loc_3);
                _loc_2++;
            }
            return;
        }// end function

        public function readSceneEffect(param1:Object) : void
        {
            this._sceneEffects = SceneEffectParser.fromObj(param1);
            return;
        }// end function

        public function updateBuildLevel(param1:int, param2:int) : void
        {
            return;
        }// end function

        public function getMapSharp(param1:int) : SMapSharp
        {
            return this._sharpsMap[param1] as SMapSharp;
        }// end function

        public function initSharpRawData(param1:int, param2:Boolean) : void
        {
            var _loc_4:int = 0;
            var _loc_5:Array = null;
            var _loc_6:SPoint = null;
            var _loc_7:Dictionary = null;
            if (this._sharpsUpdater)
            {
                if (this._sharpsUpdater[param1] == param2)
                {
                    return;
                }
            }
            var _loc_3:* = this._sharpsMap[param1] as SMapSharp;
            if (_loc_3)
            {
                _loc_5 = _loc_3.points;
                _loc_7 = this._sharpsRawData[param1] as Dictionary;
                if (_loc_7 == null)
                {
                    _loc_7 = new Dictionary();
                    for each (_loc_6 in _loc_5)
                    {
                        
                        this.setMapDataByPoint(_loc_7, _loc_6.x, _loc_6.y);
                    }
                    this._sharpsRawData[param1] = _loc_7;
                }
            }
            return;
        }// end function

        public function setMapDataBySharp(param1:int, param2:Boolean) : void
        {
            var _loc_4:int = 0;
            var _loc_5:Array = null;
            var _loc_6:SPoint = null;
            var _loc_7:Dictionary = null;
            if (this._sharpsUpdater)
            {
                if (this._sharpsUpdater[param1] == param2)
                {
                    return;
                }
            }
            var _loc_3:* = this._sharpsMap[param1] as SMapSharp;
            if (_loc_3)
            {
                _loc_5 = _loc_3.points;
                _loc_7 = this._sharpsRawData[param1] as Dictionary;
                if (_loc_7 == null)
                {
                    _loc_7 = new Dictionary();
                    for each (_loc_6 in _loc_5)
                    {
                        
                        this.setMapDataByPoint(_loc_7, _loc_6.x, _loc_6.y);
                    }
                    this._sharpsRawData[param1] = _loc_7;
                }
                if (param2)
                {
                    _loc_4 = _loc_3.type.__value;
                    for each (_loc_6 in _loc_5)
                    {
                        
                    }
                }
                else
                {
                    for each (_loc_10 in _loc_5)
                    {
                        
                        _loc_6 = _loc_9[_loc_8];
                    }
                }
            }
            return;
        }// end function

        private function setMapDataByPoint(param1:Dictionary, param2:int, param3:int) : void
        {
            var _loc_4:* = GameMapUtil.getPointValue(param2, param3);
            param1[param2 * 10000 + param3] = GameMapUtil.getPointValue(param2, param3);
            return;
        }// end function

        private function getMapDataValue(param1:Dictionary, param2:int, param3:int) : int
        {
            return param1[param2 * 10000 + param3];
        }// end function

        public function get isSpa() : Boolean
        {
            return this._isSpa;
        }// end function

        public function getFishingNearPoint() : Point
        {
            return new Point(128, 171);
        }// end function

        public function isPassPointToMap(param1:int, param2:int = -1) : Boolean
        {
            if (param2 == -1)
            {
                var _loc_4:* = MapFileUtil.mapID;
                param2 = MapFileUtil.mapID;
            }
            var _loc_3:* = this.getPassPointInfo(param1);
            if (_loc_3 && _loc_3.passTo)
            {
                if (_loc_3.passTo[0] != null && _loc_3.passTo[0] is SPassTo)
                {
                    return (_loc_3.passTo[0] as SPassTo).mapId == param2;
                }
            }
            return false;
        }// end function

        private function parseClientData() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:SNpc = null;
            var _loc_4:SMapSharp = null;
            var _loc_5:NPCInfo = null;
            var _loc_6:Array = null;
            var _loc_7:SPoint = null;
            var _loc_8:SPoint = null;
            var _loc_9:CrossMainCityStatueInfo = null;
            var _loc_10:* = new Dictionary();
            this._sharpsMap = new Dictionary();
            _loc_1 = 0;
            while (_loc_1 < this._sMapDefine.sharps.length)
            {
                
                _loc_4 = this._sMapDefine.sharps[_loc_1];
                var _loc_10:* = _loc_4;
                this._sharpsMap[_loc_4.sharpId] = _loc_4;
                _loc_1++;
            }
            var _loc_10:* = new Dictionary();
            this._sharpsRawData = new Dictionary();
            var _loc_10:* = this._sMapDefine.passPoints.concat();
            this._passInfos = this._sMapDefine.passPoints.concat();
            for each (_loc_12 in this._sMapDefine.npcs)
            {
                
                _loc_3 = _loc_11[_loc_10];
                _loc_5 = new NPCInfo();
                var _loc_12:* = _loc_3;
                _loc_5.snpc = _loc_3;
                if (_loc_5.tnpc)
                {
                    var _loc_12:* = !_loc_5.tnpc.defaultType;
                    _loc_5.isAddStage = !_loc_5.tnpc.defaultType;
                }
                this._npcInfos.push(_loc_5);
            }
            var _loc_10:* = [];
            this._jumpPoints = [];
            if (this._sMapDefine.jumpPointSeq != null)
            {
                for each (_loc_12 in this._sMapDefine.jumpPointSeq)
                {
                    
                    _loc_6 = _loc_11[_loc_10];
                    _loc_7 = _loc_6[0] as SPoint;
                    _loc_8 = _loc_6[(_loc_6.length - 1)] as SPoint;
                    this._jumpPoints.push(_loc_7);
                    this._jumpPoints.push(_loc_8);
                }
            }
            var _loc_10:* = [];
            this._crossMainCityStatueInfos = [];
            if (this._sMapDefine.mapId == 80000)
            {
                _loc_9 = new CrossMainCityStatueInfo();
                var _loc_10:int = 1;
                _loc_9.id = 1;
                var _loc_10:int = 80000;
                _loc_9.mapId = 80000;
                var _loc_10:int = 6548;
                _loc_9.x = 6548;
                var _loc_10:int = 3353;
                _loc_9.y = 3353;
                this._crossMainCityStatueInfos.push(_loc_9);
            }
            return;
        }// end function

        public function updateMainCityInfo(param1:SMainCityStatues) : void
        {
            var _loc_2:CrossMainCityStatueInfo = null;
            if (this._crossMainCityStatueInfos && this._crossMainCityStatueInfos.length > 0)
            {
                _loc_2 = this._crossMainCityStatueInfos[0];
                var _loc_3:* = param1;
                _loc_2.mainCityStatus = param1;
            }
            return;
        }// end function

    }
}
